//
//  CYFinanceInvestTopCell.m
//  cyjf
//
//  Created by tauCross on 2017/9/25.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYFinanceInvestTopCell.h"



@implementation CYFinanceInvestTopCellObject

@end



@interface CYFinanceInvestTopCell ()

@property(nonatomic, strong)UIImageView *backgroundImageView;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UILabel *rateLabel;
@property(nonatomic, strong)UILabel *dueLabel;

@end


@implementation CYFinanceInvestTopCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.backgroundImageView = [[UIImageView alloc] init];
        self.backgroundImageView.image = [UIImage gradientImageFromColors:@[APP_DEFAULT_COLOR_RED, HEXCOLOR(@"F7694E")] ByGradientType:UIImageGradientTypeTopToBottom size:CGSizeMake(10, 86)];
        [self.contentView addSubview:self.backgroundImageView];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.textColor = HEXCOLOR(@"FFFFFF");
        self.titleLabel.font = [UIFont systemFontOfSize:18];
        [self.contentView addSubview:self.titleLabel];
        
        self.rateLabel = [[UILabel alloc] init];
        self.rateLabel.textColor = HEXCOLOR(@"FFFFFF");
        self.rateLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.rateLabel];
        
        self.dueLabel = [[UILabel alloc] init];
        self.dueLabel.textColor = HEXCOLOR(@"FFFFFF");
        self.dueLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.dueLabel];
    }
    return self;
}

+ (CGFloat)heightForObject:(id)object atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
    return 90;
}

- (BOOL)shouldUpdateCellWithObject:(CYFinanceInvestTopCellObject *)object
{
    self.titleLabel.text = SAFE_STRING(object.title);
    
    self.rateLabel.text = [NSString stringWithFormat:@"预期年化收益率:%.2f%%", object.rate.doubleValue];
    
    self.dueLabel.text = [NSString stringWithFormat:@"投资期限:%.0f天", object.due.doubleValue];

    [self setNeedsLayout];
    return YES;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.backgroundImageView.frame = self.contentView.bounds;
    
    [self.titleLabel sizeToFit];
    self.titleLabel.left = 20;
    self.titleLabel.centerY = 33;
    
    [self.rateLabel sizeToFit];
    self.rateLabel.left = 20;
    self.rateLabel.centerY = 63;
    
    [self.dueLabel sizeToFit];
    self.dueLabel.right = self.contentView.width - 20;
    self.dueLabel.centerY = self.rateLabel.centerY;
}

@end
